// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   PmsResourceServiceImpl.java

package com.hfstu.pms.dataaccess.service.impl;

import com.google.common.collect.Lists;
import com.hfstu.framework.core.orm.Page;
import com.hfstu.framework.core.orm.PageRequest;
import com.hfstu.framework.util.StringUtil;
import com.hfstu.pms.common.PmsCombinationType;
import com.hfstu.pms.common.PmsResourceType;
import com.hfstu.pms.dataaccess.dao.IPmsResourceDao;
import com.hfstu.pms.dataaccess.service.IPmsResourceService;
import com.hfstu.pms.model.PmsResource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

public class PmsResourceServiceImpl
	implements IPmsResourceService
{

	private IPmsResourceDao pmsResourceDao;

	public PmsResourceServiceImpl()
	{
		pmsResourceDao = null;
	}

	public PmsResource save(PmsResource entity)
	{
		return (PmsResource)pmsResourceDao.save(entity);
	}

	public void saveRoleResource(String roleId, Map map)
	{
		String systemCode = (String)map.get("systemCode");
		pmsResourceDao.deleteResourceById(roleId, systemCode);
		String menuIds = (String)map.get("menuIds");
		String menuNavIds = (String)map.get("menuNavIds");
		String navControlIds = (String)map.get("navControlIds");
		String navIds = (String)map.get("navIds");
		String controlRegisterIds = (String)map.get("controlRegisterIds");
		String controlFuncIds = (String)map.get("controlFuncIds");
		List pmsResources = Lists.newArrayList();
		if (!StringUtil.isNullOrEmpty(menuIds))
		{
			String menuIdArray[] = menuIds.split(",");
			String as[];
			int j1 = (as = menuIdArray).length;
			for (int i = 0; i < j1; i++)
			{
				String menuId = as[i];
				PmsResource pr = new PmsResource();
				pr.setSystemCode(systemCode);
				pr.setNodeId(roleId);
				pr.setCombinationType(PmsCombinationType.ROLE_RESOURCE.getKey());
				pr.setResourceType(PmsResourceType.MENU.getKey());
				pr.setMenuId(StringUtil.clean(menuId));
				pmsResources.add(pr);
			}

		}
		if (!StringUtil.isNullOrEmpty(menuNavIds))
		{
			String menuNavIdArray[] = menuNavIds.split(",");
			String as1[];
			int k1 = (as1 = menuNavIdArray).length;
			for (int j = 0; j < k1; j++)
			{
				String menuNavId = as1[j];
				PmsResource pr = new PmsResource();
				pr.setSystemCode(systemCode);
				pr.setNodeId(roleId);
				pr.setCombinationType(PmsCombinationType.ROLE_RESOURCE.getKey());
				pr.setResourceType(PmsResourceType.MENUNAV.getKey());
				pr.setMenuNavId(StringUtil.clean(menuNavId));
				pmsResources.add(pr);
			}

		}
		if (!StringUtil.isNullOrEmpty(navControlIds))
		{
			String navControlIdArray[] = navControlIds.split(",");
			String as2[];
			int l1 = (as2 = navControlIdArray).length;
			for (int k = 0; k < l1; k++)
			{
				String navControlId = as2[k];
				String navControls[] = navControlId.split("_");
				PmsResource pr = new PmsResource();
				pr.setSystemCode(systemCode);
				pr.setNodeId(roleId);
				pr.setCombinationType(PmsCombinationType.ROLE_RESOURCE.getKey());
				pr.setResourceType(PmsResourceType.NAVCONTROL.getKey());
				pr.setNavControlId(navControls[0]);
				pr.setMenuNavId(navControls[1]);
				pr.setMenuId(navControls[2]);
				pmsResources.add(pr);
			}

		}
		if (!StringUtil.isNullOrEmpty(navIds))
		{
			String navIdArray[] = navIds.split(",");
			String as3[];
			int i2 = (as3 = navIdArray).length;
			for (int l = 0; l < i2; l++)
			{
				String navId = as3[l];
				String navs[] = navId.split("_");
				PmsResource pr = new PmsResource();
				pr.setSystemCode(systemCode);
				pr.setNodeId(roleId);
				pr.setCombinationType(PmsCombinationType.ROLE_RESOURCE.getKey());
				pr.setResourceType(PmsResourceType.NAVIGATION.getKey());
				pr.setNavId(navs[0]);
				pr.setMenuNavId(navs[1]);
				pr.setMenuId(navs[2]);
				pmsResources.add(pr);
			}

		}
		StringUtil.isNullOrEmpty(controlRegisterIds);
		if (!StringUtil.isNullOrEmpty(controlFuncIds))
		{
			String controlFuncIdArray[] = controlFuncIds.split(",");
			String as4[];
			int j2 = (as4 = controlFuncIdArray).length;
			for (int i1 = 0; i1 < j2; i1++)
			{
				String controlFuncId = as4[i1];
				String controlFuncs[] = controlFuncId.split("_");
				PmsResource pr = new PmsResource();
				pr.setSystemCode(systemCode);
				pr.setNodeId(roleId);
				pr.setCombinationType(PmsCombinationType.ROLE_RESOURCE.getKey());
				pr.setResourceType(PmsResourceType.CONTROLFUNC.getKey());
				pr.setControlFuncId(controlFuncs[0]);
				if (controlFuncs.length == 2)
				{
					pr.setMenuId(controlFuncs[1]);
				} else
				{
					if (controlFuncs.length != 4)
						continue;
					pr.setNavId(controlFuncs[1]);
					pr.setMenuNavId(controlFuncs[2]);
					pr.setMenuId(controlFuncs[3]);
				}
				pmsResources.add(pr);
			}

		}
		pmsResourceDao.saveLists(pmsResources);
	}

	public PmsResource update(PmsResource entity)
	{
		return (PmsResource)pmsResourceDao.update(entity);
	}

	public PmsResource saveOrUpdate(PmsResource entity)
	{
		return (PmsResource)pmsResourceDao.saveOrUpdate(entity);
	}

	public void delete(String id)
	{
		pmsResourceDao.delete(id);
	}

	public void delete(PmsResource entity)
	{
		pmsResourceDao.delete(entity);
	}

	public PmsResource getById(String id)
	{
		return (PmsResource)pmsResourceDao.getById(id);
	}

	public List getByIds(String ids[])
	{
		return pmsResourceDao.getByIds(ids);
	}

	public List findAll()
	{
		return pmsResourceDao.findAll();
	}

	public List findListByCondition(Map filterPropertyMap, Map sortValueMap)
	{
		return pmsResourceDao.findListByCondition(filterPropertyMap, sortValueMap);
	}

	public Page findPageByCondition(PageRequest pageRequest, Map filterPropertyMap, Map sortValueMap)
	{
		return pmsResourceDao.findPageByCondition(pageRequest, filterPropertyMap, sortValueMap);
	}

	public IPmsResourceDao getPmsResourceDao()
	{
		return pmsResourceDao;
	}

	public void setPmsResourceDao(IPmsResourceDao pmsResourceDao)
	{
		this.pmsResourceDao = pmsResourceDao;
	}

	public volatile Object getById(Serializable serializable)
	{
		return getById((String)serializable);
	}

	public volatile Object save(Object obj)
	{
		return save((PmsResource)obj);
	}

	public volatile Object saveOrUpdate(Object obj)
	{
		return saveOrUpdate((PmsResource)obj);
	}

	public volatile void delete(Object obj)
	{
		delete((PmsResource)obj);
	}

	public volatile void delete(Serializable serializable)
	{
		delete((String)serializable);
	}

	public volatile List getByIds(Serializable aserializable[])
	{
		return getByIds((String[])aserializable);
	}

	public volatile Object update(Object obj)
	{
		return update((PmsResource)obj);
	}
}
